package com.guigu.serviceorder.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.serviceorder.entity.TbReturnOrderItem;
import com.guigu.serviceorder.service.ITbReturnOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-07-08
 */
@RestController
@CrossOrigin
@RequestMapping("/returnOrde")
public class TbReturnOrderItemController {

    @Autowired
    private ITbReturnOrderItemService iTbReturnOrderItemService;

    // 分页条件查询
    @PostMapping("/findPage")
    public Result findPage(@RequestBody Map<String, Object> searchMap, Integer page, Integer size) {
        return iTbReturnOrderItemService.findPage(searchMap, page, size);
    }

    @PostMapping("/add")
    public Result insert(@RequestBody TbReturnOrderItem tbReturnOrderItem){
        if (iTbReturnOrderItemService.save(tbReturnOrderItem)==true)
            return Result.ok();
        return  Result.error();
    }

    @GetMapping("/delete")
    public Result delete(Long id){
        if(iTbReturnOrderItemService.removeById(id))
            return Result.ok();
        return Result.error();

    }
    @PostMapping("/update")
    public Result update(@RequestBody TbReturnOrderItem tbReturnOrderItem){
        if (iTbReturnOrderItemService.updateById(tbReturnOrderItem))
            return Result.ok();
        return Result.error();
    }

    @GetMapping("/findById")
    public Result findById(Long id) {
        TbReturnOrderItem tbReturnOrderItem = iTbReturnOrderItemService.getById(id);
        if (tbReturnOrderItem == null) {
            return Result.error();
        }
        return Result.ok().data("tbReturnOrderItem", tbReturnOrderItem);
    }
}

